using System;
using System.Collections.ObjectModel;
using System.Linq;
using Telerik.Windows.Data;

namespace Rio.Framework.Pages.Controls.Navigation
{
	public class DropDownButtonViewModel : ButtonViewModel
    {
        #region Fields 

        private ObservableItemCollection<MenuItemViewModel> menuItems;

        #endregion

        #region Properties 

        /// <summary>
        /// Gets the menu items.
        /// </summary>
        /// <value>The menu items.</value>
        public ObservableItemCollection<MenuItemViewModel> MenuItems
        {
            get
            {
                return menuItems;
            }
        }

        /// <summary>
        /// Gets or sets the is enabled.
        /// </summary>
        /// <value>
        /// The is enabled.
        /// </value>
        public new bool IsEnabled
        {
            get
            {
                if (MenuItems != null && MenuItems.All(p => p.IsEnabled == false))
                {
                    return false;
                }
                return true;
            }
        }

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="DropDownButtonViewModel"/> class.
        /// </summary>
        public DropDownButtonViewModel()
        {
            menuItems = new ObservableItemCollection<MenuItemViewModel>();
            menuItems.ItemChanged += menuItems_ItemChanged;
        }

        /// <summary>
        /// Handles the ItemChanged event of the menuItems control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Telerik.Windows.Data.ItemChangedEventArgs&lt;Rio.Framework.Pages.Controls.Navigation.MenuItemViewModel&gt;"/> instance containing the event data.</param>
        private void menuItems_ItemChanged(object sender, ItemChangedEventArgs<MenuItemViewModel> e)
        {
            OnPropertyChanged("IsEnabled");
        }

        #endregion

    }
}
